package com.letoken.platform.repo.app.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.repo.admin.req.user.FundRankingListBonusRecordReq;
import com.letoken.platform.repo.admin.req.user.RankingDetailReq;
import com.letoken.platform.repo.app.po.AppFundDetail;
import com.letoken.platform.repo.app.po.AppRankingDetail;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 作者
 * @since 2023-09-19
 */
public interface AppRankingDetailMapper extends BaseMapper<AppRankingDetail> {
    @Select("select IFNULL(sum(amount),0) from app_ranking_detail where type =#{type} GROUP BY create_time  ORDER BY create_time desc limit 1")
   BigDecimal getRankingSum(@Param("type")Integer type);

    @Select("select IFNULL(sum(amount),0) from app_ranking_detail where type =#{type}")
    BigDecimal getRanking(@Param("type")Integer type);

   Page<AppRankingDetail> getRankingDetail(@Param("page") Page<AppRankingDetail> page, @Param("req") RankingDetailReq req);


    Page<AppRankingDetail> page(@Param("page") Page<AppRankingDetail> page ,@Param("params") FundRankingListBonusRecordReq params);

    @Select("select *,type,create_time createtime,(select head_portrait from app_user where id=user_id) headUrl  from app_ranking_detail where DATE(create_time) =(  select DATE(create_time) from app_ranking_detail where type = #{type} ORDER BY id desc  limit 1) and type = #{type} ORDER BY ranking ASC")
    List<AppRankingDetail> getDetail(@Param("type")Integer type);



}
